package com.aos.erp.manager.service.mq;

import com.alibaba.fastjson.JSON;
import com.aos.erp.common.bean.ResultBean;
import com.aos.erp.common.exception.BizException;
import com.aos.erp.manager.remote.model.SynUser;
import com.aos.erp.manager.remote.model.User;
import com.aos.erp.manager.remote.sys.SynUserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * @program: erp
 * @description: 消息接受
 * @author: tanzhiyu
 * @create: 2018-11-19 14:53
 **/
@Slf4j
@Component
public class SynUserReceiveMessage {
    @Resource
    SynUserService synUserService;

    @RabbitHandler
    @RabbitListener(queues = QueueConstants.USER_QUEUE_SAVE)
    public void save(SynUser synUser) throws BizException {
        ResultBean o = synUserService.synUserInfo(synUser);
        if (ResultBean.CODE_FAIL == o.getCode()) {
            throw new BizException(o.getErrMsg());
        }
    }

    @RabbitHandler
    @RabbitListener(queues = QueueConstants.USER_QUEUE_DEL)
    public void del(SynUser synUser) throws BizException {
        ResultBean o = synUserService.deleteUser(synUser.getAppCode(), synUser.getUsername());
        if (ResultBean.CODE_FAIL == o.getCode()) {
            throw new BizException(o.getErrMsg());
        }
    }

    /*@RabbitHandler
    @RabbitListener(queues = QueueConstants.USER_ROLE_QUEUE_SAVE)
    public void addUser(User user) throws BizException {
        ResultBean o = synUserService.addUser(user);
        if (ResultBean.CODE_FAIL == o.getCode()) {
            throw new BizException(o.getErrMsg());
        }
    }*/
}
